package LeetCode;

import java.util.LinkedList;
import java.util.List;

/**
 * @Author: Dijah
 * @Date: 2023/2/7 14:46
 * @Desc: https://leetcode.cn/problems/combinations/
 * 回溯算法 。组合
 */
public class code77_solution {

   static List<List<Integer>> res = new LinkedList<>();
    //记录回溯算法的递归路径
   static LinkedList<Integer> track = new LinkedList<>();

    public static List<List<Integer>> combine(int n, int k) {
        backtrack(1,n,k);
        return res;
    }

    public static void backtrack(int start,int n ,int k){
        //base case
        if(k == track.size()){
            res.add(new LinkedList<>(track));//路径加入到res中
            return;
        }

        //回溯
        for(int i = start; i <= n; i++){
            //做出选择
            track.addLast(i);
            //干点事
            backtrack(i+1,n,k);
            //撤销选择
            track.removeLast();
        }

    }

    public static void main(String[] args) {
        List<List<Integer>> combine = combine(4, 2);
        for (int i = 0; i < combine.size(); i++) {

        }
    }
}
